home *** CD-ROM | disk | FTP | other *** search
- #include "IsAppRunning.h"
-
-
- // check to see using the process manager whether our
- // target app is running
-
- Boolean IsAppRunning( OSType targetType,
- OSType targetSignature,
- ProcessSerialNumber *targetPSN,
- ProcessInfoRec *targetPIRec,
- StringPtr targetName )
- {
-
- // we want to return the PSN if there is one
- // we want to return the Proc Info Rec if there is one
- // we will return true if we found our App
- // false if it wasn't running.
-
- // we need to loop through all the running processes and
- // find one that looks like our background task.
-
- // This is all standard stuff - see IM Process Manager, page 2-6
-
- targetPSN->highLongOfPSN = 0 ;
- targetPSN->lowLongOfPSN = kNoProcess ;
-
- // set up the info record, for the call to get process info
- targetPIRec->processInfoLength = sizeof( ProcessInfoRec ) ;
- targetPIRec->processName = targetName ; // the name will be put in here
- targetPIRec->processAppSpec = nil ; // we do not care about the location of the app
-
- // right, loop through the running processes
- while( GetNextProcess( targetPSN ) == noErr ) {
-
- if( GetProcessInformation( targetPSN, targetPIRec ) == noErr ) {
-
- if( targetPIRec->processType == targetType
- && targetPIRec->processSignature == targetSignature )
-
- return true ;
- }
- }
- return false ;
- }
-
-
- // search in the desktop database for the app so that we can launch it
- OSErr LaunchApp( OSType targetSignature)
- {
- DTPBRec theDatabase ;
- LaunchParamBlockRec theLPB ;
- FSSpec targetFSSpec ;
- OSErr err ;
-
- theDatabase.ioCompletion = 0L ;
- theDatabase.ioNamePtr = 0L ;
- theDatabase.ioVRefNum = -1 ; // restrict search to boot volume only
-
- if(( err = PBDTGetPath( &theDatabase )) != noErr )
- return err ;
-
- theDatabase.ioIndex = 0 ;
- theDatabase.ioFileCreator = targetSignature ;
- theDatabase.ioNamePtr = (StringPtr)targetFSSpec.name ;
-
- if(( err = PBDTGetAPPL( &theDatabase, false )) != noErr)
- return err ;
-
- targetFSSpec.vRefNum = theDatabase.ioVRefNum ;
- targetFSSpec.parID = theDatabase.ioAPPLParID ;
-
- theLPB.launchBlockID = extendedBlock ;
- theLPB.launchEPBLength = extendedBlockLen ;
- theLPB.launchFileFlags = 0 ;
- theLPB.launchControlFlags = launchContinue + launchNoFileFlags + launchUseMinimum ;
- theLPB.launchAppSpec = &targetFSSpec ;
- theLPB.launchAppParameters = 0L ;
-
- return( LaunchApplication( &theLPB ) ) ;
- }
-